export default function (url, options) {
  const config = useRuntimeConfig();
  let nuxtApp = useNuxtApp();
  return useFetch(url, {
    baseURL: config.public.baseURL,
    onRequest({ options }) {
      if (import.meta.env.SSR) {
        options.headers = {
          token: "fds",
          ...options.headers,
        };
      }
    },
    onResponse({ response }) {
      if (response.status !== 200) {
        if (import.meta.client) {
          ElMessage.error("登录过期");
        }
        {
          console.log("-=-=服务的");

          nuxtApp.runWithContext(() => navigateTo("/login"));
        }
      }
    },
    ...options,
  }).data.value;
}
